package org.yray.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
    public static void main(String[] args) throws IOException {
        System.out.println("tcp协议服务器端启动");
        ServerSocket serverSocket = new ServerSocket(8080);
        //接收客户端请求
        Socket accept = serverSocket.accept();
        InputStream inputStream = accept.getInputStream();
        //将字节流转换成String类型
        byte[] bytes = new byte[1024];
        int len = inputStream.read(bytes);
        String result = new String(bytes, 0, len);
        System.out.println("服务器端接收客户端内容:" + result);
        serverSocket.close();
    }
}
